package com.erplan.studentmgt.desktop.elements;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;

import com.erplan.studentmgt.desktop.StudentMgt;

public class AppStatusBar {
	static Label statusBarTxt = null;

	public static void init(){
		StudentMgt.statusBarArea = new Composite(StudentMgt.shell, SWT.NONE);
		GridLayout statusAreaLayout = new GridLayout();
		statusAreaLayout.makeColumnsEqualWidth = true;
		statusAreaLayout.horizontalSpacing = 0;
		statusAreaLayout.marginHeight = 0;
		statusAreaLayout.marginWidth = 0;
		statusAreaLayout.verticalSpacing = 0;
		StudentMgt.statusBarArea.setLayout(statusAreaLayout);
		GridData statusAreaLData = new GridData();
		statusAreaLData.horizontalAlignment = GridData.FILL;
		statusAreaLData.grabExcessHorizontalSpace = true;
		StudentMgt.statusBarArea.setLayoutData(statusAreaLData);

		statusBarTxt = new Label(StudentMgt.statusBarArea, SWT.BORDER);
		statusBarTxt.setText("Ready");
		GridData txtStatusLData = new GridData();
		txtStatusLData.horizontalAlignment = GridData.FILL;
		txtStatusLData.grabExcessHorizontalSpace = true;
		txtStatusLData.verticalIndent = 3;
		statusBarTxt.setLayoutData(txtStatusLData);
	}

	static Listener armListener = new Listener() {
		public void handleEvent(Event event) {
			MenuItem item = (MenuItem) event.widget;
			statusBarTxt.setText(item.getText());
			statusBarTxt.update();
		}
	};
	static Listener showListener = new Listener() {
		public void handleEvent(Event event) {
			Menu menu = (Menu) event.widget;
			MenuItem item = menu.getParentItem();
			if (item != null) {
				statusBarTxt.setText(item.getText());
				statusBarTxt.update();
			}
		}
	};
	static Listener hideListener = new Listener() {
		public void handleEvent(Event event) {
			statusBarTxt.setText("");
			statusBarTxt.update();
		}
	};
}